/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session;

import entity.Player;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.ejb.Remove;
import javax.ejb.Stateful;
import session.manager.PlayerManagerBeanLocal;

/**
 *
 * @author antonio, giuseppe
 */
@Stateful
public class GameSessionBean implements GameSessionBeanLocal {
    
    private static final Logger log = Logger.getLogger(GameSessionBean.class.getName());
    
    private Player player;
    
    @EJB
    private PlayerManagerBeanLocal playerManager;
    
    @Override
    public void initPlayer(String username) {
        this.player = this.playerManager.find(username);
    }
    
    @Override
    public Player getPlayer() {
        return this.player;
    }
    
    @Override
    public void setPlayer(Player player) {
        this.player = player;
    }
    
    @Remove
    @Override
    public void remove() {
        log.log(Level.INFO, "Logged out of: {0}", this.player.getUsername());
    }

}
